"""
@Author：十
@Time：2024/8/1 17:24
@FileName：instrument.py
@Description：仪器信息实现
"""
import sys

from PyQt5.QtCore import Qt
from PyQt5.QtWidgets import QApplication
from pyqt5_plugins.examplebutton import QtWidgets
from UI.instrument import Ui_Form


class InstrumentWindow(QtWidgets.QWidget, Ui_Form):
    def __init__(self, parent=None):
        super(InstrumentWindow, self).__init__()

        self.setAttribute(Qt.WA_DeleteOnClose)

        self.parent = parent
        self.instrument = None

        self.setupUi(self)

        self.pushButton.clicked.connect(self.Confirm)

    def Confirm(self):
        # 设备信息
        try:
            self.instrument = {
                'Factory': self.lineEdit_Factory.text(),
                'ID': self.lineEdit_ID.text(),
                'Type': self.comboBox_Type.currentText()
            }
            self.parent.Signal_Get_Instrument.emit(self.instrument)
            self.close()
        except Exception as e:
            print('Get Instrument Error:', e)

    # 关闭窗口销毁
    # def closeEvent(self, event):
    #     self.setAttribute(Qt.WA_DeleteOnClose)


if __name__ == '__main__':
    app = QApplication(sys.argv)
    mainWindow = InstrumentWindow()
    mainWindow.show()
    sys.exit(app.exec_())
